package com.css.crm.vo;


import java.io.Serializable;
import java.util.ArrayList;

public class MenuMap implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	public static MenuMap menuMapInstance;	
	MenuMap(){}
	
	private String applId;
	private String applDispName;
	private String rtmuId;
	private String rootName;
	private String rootUrl;
	private ArrayList<MenuGroup> menuGroupList;
	
	public ArrayList<MenuItem> getCurrentAccessPath(String menuItemId){
		
		ArrayList<MenuItem> temp = new ArrayList<MenuItem>();
		
		MenuItem rootItem = new MenuItem();
		
		rootItem.setMenuId(rtmuId);		
		rootItem.setMenuName(rootName);
		rootItem.setUrl(rootUrl);
		temp.add(rootItem);
		
		if (menuItemId != null){
			
			MenuGroup mGroup = getMenuGroup(menuItemId);
			
			if (mGroup!=null)
			{
				MenuItem groupItem = new MenuItem();
				groupItem.setMenuId(mGroup.getMugpId());		
				groupItem.setMenuName(mGroup.getGroupName());
				temp.add(groupItem);
				
				MenuItem mItem = getMenuItem(menuItemId);
				temp.add(mItem);
			}
		}		
		
		return temp;
	}	
	
	public String getRootUrl() {
		return rootUrl;
	}

	public void setRootUrl(String rootUrl) {
		this.rootUrl = rootUrl;
	}

	public String getMenuItemIdByViewId(String viewId){
		
		if (viewId.endsWith("menu.xhtml"))
			return rtmuId;
		
		for(MenuGroup mGroup : menuGroupList){
			for(MenuItem mItem : mGroup.getMenuItemList()){
				for(MenuFunc mFunc : mItem.getMenuFuncList()){
					if (mFunc.getFuncUrl().endsWith(viewId))
						return mFunc.getParentId();
				}
			}
		}
		return null;
	}
		
	public MenuGroup getMenuGroup(String menuItemId){
		
		for(MenuGroup mGroup : menuGroupList){
			for(MenuItem mItem : mGroup.getMenuItemList()){
				if (mItem.getMenuId().equals(menuItemId))
					return (MenuGroup)mGroup.clone();
			}
		}
		return null;
	}
	
	public MenuItem getMenuItem(String menuItemId){
		
		if (menuItemId!=null){		
			for(MenuGroup mGroup : menuGroupList){
				for(MenuItem mItem : mGroup.getMenuItemList()){
					if (mItem.getMenuId().equals(menuItemId))
						return (MenuItem)mItem.clone();
				}
			}
		}		
		return null;
	}

	public String getApplId() {
		return applId;
	}
	public void setApplId(String applId) {
		this.applId = applId;
	}
	public String getRtmuId() {
		return rtmuId;
	}
	public void setRtmuId(String rtmuId) {
		this.rtmuId = rtmuId;
	}
	public ArrayList<MenuGroup> getMenuGroupList() {
		return menuGroupList;
	}
	public void setMenuGroupList(ArrayList<MenuGroup> menuGroupList) {
		this.menuGroupList = menuGroupList;
	}

	public String getApplDispName() {
		return applDispName;
	}

	public void setApplDispName(String applDispName) {
		this.applDispName = applDispName;
	}	
}
